'use strict';

const vinylFs = require('vinyl-fs');
const stylus = require('gulp-stylus');
const nib = require('nib');
const util = require('util');
const cfgUtil = require('../../app/server/commons/factories/configuration');
const serverCfg = cfgUtil.get('server');
module.exports = function (src, dest, resolve, reject) {
  vinylFs.src(src).pipe(stylus({
    compress: true,
    use: [
      nib()
    ],
    globals: {
      '$STATIC_PATH': ''
    },
    functions: {
      url: stylus.stylus.url({
        paths: [serverCfg.STATIC_DIR]
      })
    }
  })).on('error', function (err) {
    if (util.isFunction(reject)) {
      reject(err);
    }
  }).on('end', function () {
    if (util.isFunction(resolve)) {
      setTimeout(function () {
        resolve();
      }, 100);
    }
  }).pipe(vinylFs.dest(dest));
};
